<template>
	<view class="login clearfix">
		<!-- logo -->
		<view class="logo">
			<image src="../../static/image/logo.png" mode=""></image>
		</view>
		<!-- 登录页 -->
		<view class="login_con">
			<h2>登录</h2>
			<p>欢迎来到油井计量，请使用手机账号登陆</p>
			<view class="input">
				<input type="text" v-model="phone" placeholder="输入手机号码">
				<input type="password" v-model="password" placeholder="输入账户密码">
			</view>
			<span @click="forgetPass">忘记密码？</span>
			<button class="btn_login" @click="loginBtn">确定</button>
		</view>
	</view>
</template>

<script>
	import {
		throtTling
	} from '../../utils/throttling.js'
	export default {
		data() {
			return {
				phone: '',
				password: ''
			}
		},
		methods: {
			loginBtn: throtTling(function() {
				let that = this
				let data = {
					phone: this.phone,
					password: this.password
				}
				this.$http({
					url: '/wxapi/UserApi/login',
					data: data,
					method: 'POST'
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						try {
							uni.setStorageSync('token', res.data.token);
							uni.reLaunch({
								url: '../deviceList/deviceList'
							})
						} catch (e) {
							return 
						}


					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}).catch(err => {
					alert(err)
				})
			}, 1000),
			forgetPass() {
				uni.navigateTo({
					url: '../forgetPass/forgetPass'
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.login {
		.logo {
			margin: 180rpx auto;
			width: 370rpx;
			height: 93rpx;

			image {
				width: 100%;
				height: 100%;
			}
		} 
  
		.login_con {
			padding: 0 68rpx;
			font-size: 24rpx;
			color: #2E2E2E;
			background: url(../../static/image/login_bg.png) no-repeat;
			background-size: 100% 100%;

			h2 {
				margin-bottom: 26rpx;
				font-size: 48rpx;
				color: #2E2E2E;
				font-weight: 700;
				font-family: PingFang SC;
			}

			.input {
				margin: 140rpx 0;

				input {
					height: 120rpx;
					font-size: 30rpx;
					color: #999;
					border-bottom: 1px solid #DDDDDD;
				}
			}

			span {
				float: right;
				font-size: 30rpx;
				color: #2596FF;
			}

			.btn_login {
				margin-top: 280rpx;
				width: 100%;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				color: #fff;
				font-size: 34rpx;
				background-color: #2596FF;
				border-radius: 40rpx;
			}
		}
	}
</style>
